import router from "./../router";
import request from "./../utils/request";
const state = {
  step: {
    payAccount: "123456",
    receiverAccount: {
      payType: "alipay",
      number: "1000000"
    }
  }
};

const actions = {
  async submitStepForm({ commit }, { params }) {
    await request({
      url: "/api/form",
      method: "POST",
      data: params
    });
    commit("saveStepFormData", { params });
    router.push("/form/step-form/result");
  }
};

const mutations = {
  saveStepFormData(state, { params }) {
    //使用es6 将新的参数一次性覆盖老的值，避免一个个的覆盖
    state.step = {
      ...state.step,
      ...params
    };
  }
};

export default {
  namespaced: true,
  state,
  actions,
  mutations
};
